﻿package com.game.btnClass
{
	import flash.display.*;
	import flash.events.*;
	
	public class AddMouseEvent extends Object
	{
		protected var _clickFun:Function;
		protected var _mouseOut:Function;
		protected var _mouseOver:Function;
		protected var _sp:DisplayObject;
		protected var _isTartget:Boolean;
		
		public function AddMouseEvent(sp:DisplayObject, click:Function = null, mouseOut:Function = null, mouseOver:Function = null,isTarget:Boolean=false)
		{
			this._sp = sp;
			this._clickFun = click;
			this._mouseOut = mouseOut;
			this._mouseOver = mouseOver;
			
			
			this._isTartget=isTarget;
			sp.addEventListener(MouseEvent.MOUSE_OUT, this.mouseOut);
			sp.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOver);
			sp.addEventListener(MouseEvent.CLICK, this.onClick);
		}
		
		protected function mouseOut(event:MouseEvent) : void
		{
			if (this._mouseOut != null)
			{
				if(_isTartget){
					this._mouseOut(event);
				}else{
					this._mouseOut();
				}
			}
		}
		
		protected function mouseOver(event:MouseEvent) : void
		{
			if (this._mouseOver != null)
			{
				if(_isTartget){
					this._mouseOver(event);
				}else{
					this._mouseOver();
				}
			}
		}
		
		protected function onClick(event:MouseEvent) : void
		{
			if (this._clickFun != null)
			{
				if(_isTartget){
					this._clickFun(event);
				}else{
					this._clickFun();
				}
			}
		}
		
		public function delMouseEvent() : void
		{
			
			if(_sp==null){
				return;
			}
			this._sp.removeEventListener(MouseEvent.MOUSE_OUT, this.mouseOut);
			this._sp.removeEventListener(MouseEvent.MOUSE_OVER, this.mouseOver);
			this._sp.removeEventListener(MouseEvent.CLICK, this.onClick);
			_clickFun=null;
			_mouseOut=null;
			_mouseOver=null;
		}
		
		
		
	}
}
